package com.bootcamp.javase.object;

import java.util.Objects;

/**
 * @program: ObjectCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-06 20:10
 **/

public class AnimalDemo {
    public static void main(String[] args) {
        String s = null;
        System.out.println(s.equals("sss"));
    }
}

class Animal{
    int age;
    String name;
    double price;

//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (!(o instanceof Animal)) return false;
//        Animal animal = (Animal) o;
//        return age == animal.age &&
//                Double.compare(animal.price, price) == 0 &&
//                name.equals(animal.name);
//    }

        @Override
    public boolean equals(Object o){
        if (this == o) return true;
        if (!(o instanceof Animal)) return false;
        Animal ao = (Animal) o;
        if (this.age!=ao.age ) return false;
        if (Double.compare(this.price,ao.price)!=0) return false;
        if (this.name==null) return ao.name==null;
        return this.name.equals(ao.name);
    }
}
